package com.fdl.common.utils;

import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

/**
 * 时间工具
 * 
 * @project: cp-website
 * @Date:2010-8-26
 * @version 1.0
 * @Company: 33e9
 * @author zhangYong.huang
 */
public class DateUtil {
	/**
	 * 年
	 */
	public static final String YEAR = "yy";
	/**
	 * 月
	 */
	public static final String MONTH = "MM";
	/**
	 * 日
	 */
	public static final String DAY_OF_MONTH = "dd";
	/**
	 * 时
	 */
	public static final String HOUR = "hh";
	/**
	 * 分
	 */
	public static final String MINUTE = "mm";
	/**
	 * 秒
	 */
	public static final String SECOND = "ss";

	private DateUtil() {
		// util class, prevent from new instance
	}

	/**
	 * 格式化当前时间
	 * 
	 * @param pattern
	 *            - ""
	 * @return the formatted date-time string
	 * @see java.text.SimpleDateFormat
	 */
	public static String formatDateTime(String pattern) {
		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(pattern);
		String now = sdf.format(new java.util.Date());
		return now;
	}

	/**
	 * 格式化参数时间
	 * 
	 * @param pattern
	 *            - ""
	 * @param date
	 *            - Date
	 * @return the formatted date-time string
	 * @see java.text.SimpleDateFormat
	 */
	public static String formatDateTime(String pattern, java.util.Date date) {
		String strDate = null;
		String strFormat = pattern;
		SimpleDateFormat dateFormat = null;

		if (date == null)
			return "";

		dateFormat = new SimpleDateFormat(strFormat);
		strDate = dateFormat.format(date);

		return strDate;
	}

	/**
	 * 格式化参数时间为当地时间
	 * 
	 * @param pattern
	 *            - ""
	 * @param date
	 *            - Date
	 * @param locale
	 *            - the locale whose date format symbols should be used
	 * @return the formatted date-time string
	 * @see java.text.SimpleDateFormat
	 */
	public static String formatDateTime(String pattern, java.util.Date date,
			Locale locale) {
		String strDate = null;
		String strFormat = pattern;
		SimpleDateFormat dateFormat = null;

		if (date == null)
			return "";

		dateFormat = new SimpleDateFormat(strFormat, locale);
		strDate = dateFormat.format(date);

		return strDate;
	}

	/**
	 * Parses a string to produce a Date.
	 * 
	 * @param pattern
	 *            - the pattern of the string
	 * @param strDateTime
	 *            - the string to be parsed
	 * @return A Date parsed from the string. In case of error, returns null.
	 */
	public static java.util.Date parse(String pattern, String strDateTime) {
		java.util.Date date = null;
		if (strDateTime == null || pattern == null)
			return null;
		try {
			SimpleDateFormat formatter = new SimpleDateFormat(pattern);
			formatter.setLenient(false);
			date = formatter.parse(strDateTime);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}

	/**
	 * 取第一个参数的年月日，第二个参数的时分秒
	 * 
	 * @param date
	 *            - the date
	 * @param time
	 *            - the time
	 * @return the composed datetime
	 */
	public static Date composeDate(Date date, Date time) {
		if (date == null || time == null)
			return null;
		Calendar c1 = Calendar.getInstance();
		c1.setTime(date);
		Calendar c2 = Calendar.getInstance();
		c2.setTime(time);
		Calendar c3 = Calendar.getInstance();
		c3.set(c1.get(Calendar.YEAR), c1.get(Calendar.MONTH), c1
				.get(Calendar.DATE), c2.get(Calendar.HOUR_OF_DAY), c2
				.get(Calendar.MINUTE), c2.get(Calendar.SECOND));
		return c3.getTime();
	}

	/**
	 * 取参数时间年月日+12:00:00
	 * 
	 * @param date
	 * @return
	 */
	public static Date getTheDate(Date date) {
		if (date == null)
			return null;
		Calendar c1 = Calendar.getInstance();
		c1.setTime(date);
		Calendar c2 = Calendar.getInstance();
		c2.set(c1.get(Calendar.YEAR), c1.get(Calendar.MONTH), c1
				.get(Calendar.DATE), 0, 0, 0);
		long millis = c2.getTimeInMillis();
		millis = millis - millis % 1000;
		c2.setTimeInMillis(millis);
		return c2.getTime();
	}

	/**
	 * 跳动日期
	 * 
	 * @param d
	 *            Date
	 * @param skipDay
	 *            可为负数
	 * @return
	 */
	public static Date skipDateTime(Date d, int skipDay) {
		if (d == null)
			return null;
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(d);
		calendar.add(Calendar.DATE, skipDay);
		return calendar.getTime();
	}

	/**
	 * 跳动小时
	 * 
	 * @param d
	 *            Date
	 * @param skipDay
	 *            可为负数
	 * @return
	 */
	public static Date skipHourTime(Date d, int skipHour) {
		if (d == null)
			return null;
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(d);
		calendar.add(Calendar.HOUR, skipHour);
		return calendar.getTime();
	}

	/**
	 * 根据时间格式来跳动时间
	 */
	public static String skipDateTime(String timeStr, int skipDay) {
		String pattern = "yyyy-MM-dd HH:mm:ss";
		Date d = parse(pattern, timeStr);
		Date date = skipDateTime(d, skipDay);
		return formatDateTime(pattern, date);
	}

	/**
	 * 根据时间格式来跳动时间 跳动小时数
	 */
	public static String skipHourTime(String timeStr, int skipHour) {
		String pattern = "yyyy-MM-dd HH:mm:ss";
		Date d = parse(pattern, timeStr);
		Date date = skipHourTime(d, skipHour);
		return formatDateTime(pattern, date);
	}

	/**
	 * 根据时间格式来跳动日期
	 */
	public static String skipDate(String dateStr, int skipDay) {
		String pattern = "yyyy-MM-dd";
		Date d = parse(pattern, dateStr);
		Date date = skipDateTime(d, skipDay);
		return formatDateTime(pattern, date);
	}

	/**
	 * 跳动日期，格式为xx年xz月xx日
	 */
	public static String skipDateThirtyDay(String dateStr, int skipDay) {
		String pattern = "yyyy-MM-dd";
		SimpleDateFormat patternFormat = new SimpleDateFormat("yyyy年MM月dd日");
		Date d = parse(pattern, dateStr);
		Date date = skipDateTime(d, skipDay);
		return patternFormat.format(date);
	}

	/**
	 * 跳动时间
	 * 
	 * @param timeStr
	 *            格式化时间字符串
	 * @param skipDay
	 *            跳动天数
	 * @param skipHour
	 *            跳动小时
	 * @param skipMinute
	 *            跳动分钟
	 * @return
	 */
	public static String getTime(String timeStr, int skipDay, int skipHour,
			int skipMinute) {
		if (null == timeStr) {
			return null;
		}

		GregorianCalendar cal = new GregorianCalendar();
		cal.setTime(parse("yyyy-MM-dd HH:mm:ss", timeStr));

		cal.add(GregorianCalendar.DAY_OF_MONTH, skipDay);
		cal.add(GregorianCalendar.HOUR_OF_DAY, skipHour);
		cal.add(GregorianCalendar.MINUTE, skipMinute);
		cal.get(GregorianCalendar.DAY_OF_WEEK_IN_MONTH);

		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");

		return dateFormat.format(cal.getTime());
	}

	/**
	 * 跳动时间
	 * 
	 * @param date
	 *            日期
	 * @param skipDay
	 *            跳动天数
	 * @param skipHour
	 *            跳动小时
	 * @param skipMinute
	 *            跳动分钟
	 * @return Date
	 */
	public static Date getTime(Date date, int skipDay, int skipHour,
			int skipMinute) {
		if (null == date) {
			return null;
		}

		GregorianCalendar cal = new GregorianCalendar();
		cal.setTime(date);

		cal.add(GregorianCalendar.DAY_OF_MONTH, skipDay);
		cal.add(GregorianCalendar.HOUR_OF_DAY, skipHour);
		cal.add(GregorianCalendar.MINUTE, skipMinute);
		cal.get(GregorianCalendar.DAY_OF_WEEK_IN_MONTH);

		return cal.getTime();
	}

	/**
	 * 参数比当前日期（精确到天）早 return true 参数比当前日期（精确到天）晚 return false
	 * 
	 * @param str
	 * @return
	 */
	public static boolean dateCompare(String str) {
		boolean bea = false;
		SimpleDateFormat sdf_d = new SimpleDateFormat("yyyy-MM-dd");
		String isDate = sdf_d.format(new java.util.Date());
		java.util.Date date1;
		java.util.Date date0;
		try {
			date1 = sdf_d.parse(str);
			date0 = sdf_d.parse(isDate);
			if (date0.after(date1)) {
				bea = true;
			}
		} catch (ParseException e) {
			bea = false;
		}
		return bea;
	}

	/**
	 * 参数比当前日期（精确到月）早 return true 参数比当前日期（精确到月）晚 return false
	 */
	public static boolean monthCompare(String str) {
		boolean bea = false;
		SimpleDateFormat sdf_m = new SimpleDateFormat("yyyy-MM");
		String isMonth = sdf_m.format(new java.util.Date());
		java.util.Date date1;
		java.util.Date date0;
		try {
			date1 = sdf_m.parse(str);
			date0 = sdf_m.parse(isMonth);
			if (date0.after(date1)) {
				bea = true;
			}
		} catch (ParseException e) {
			bea = false;
		}
		return bea;
	}

	/**
	 * 参数比当前日期（精确到秒）早 return true 参数比当前日期（精确到秒）晚 return false
	 */
	public static boolean secondCompare(String str) {
		boolean bea = false;
		SimpleDateFormat sdf_d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String isDate = sdf_d.format(new java.util.Date());
		java.util.Date date1;
		java.util.Date date0;
		try {
			date1 = sdf_d.parse(str);
			date0 = sdf_d.parse(isDate);
			if (date0.after(date1)) {
				bea = true;
			}
		} catch (ParseException e) {
			bea = false;
		}
		return bea;
	}

	/**
	 * 第一个参数比第二个参数早 return true 第一个参数比第二个参数早 return false
	 * 
	 * @param str1
	 * @param str2
	 * @return
	 */
	public static boolean secondCompare(String str1, String str2) {
		boolean bea = false;
		SimpleDateFormat sdf_d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		java.util.Date date1;
		java.util.Date date0;
		try {
			date1 = sdf_d.parse(str1);
			date0 = sdf_d.parse(str2);
			if (date0.after(date1)) {
				bea = true;
			}
		} catch (ParseException e) {
			bea = false;
		}
		return bea;
	}

	/**
	 * 根据类型来跳动当前时间
	 * 
	 * @param type
	 *            yy MM dd hh mm ss
	 * @param i
	 * @return
	 */
	public static String dateStrAdd(String type, int i) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String str = formatDateTime("yyyy-MM-dd HH:mm:ss");
		Calendar c = Calendar.getInstance();
		if (type.equals(SECOND)) {
			int s = c.get(Calendar.SECOND);
			s = s + i;
			c.set(Calendar.SECOND, s);
			str = df.format(c.getTime());
		} else if (type.equals(MINUTE)) {
			int d = c.get(Calendar.MINUTE);
			d = d + i;
			c.set(Calendar.MINUTE, d);
			str = df.format(c.getTime());
		} else if (type.equals(HOUR)) {
			int d = c.get(Calendar.HOUR);
			d = d + i;
			c.set(Calendar.HOUR, d);
			str = df.format(c.getTime());
		} else if (type.equals(DAY_OF_MONTH)) {
			int d = c.get(Calendar.DAY_OF_MONTH);
			d = d + i;
			c.set(Calendar.DAY_OF_MONTH, d);
			str = df.format(c.getTime());
		} else if (type.equals(MONTH)) {
			int d = c.get(Calendar.MONTH);
			d = d + i;
			c.set(Calendar.MONTH, d);
			str = df.format(c.getTime());
		} else if (type.equals(YEAR)) {
			int d = c.get(Calendar.YEAR);
			d = d + i;
			c.set(Calendar.YEAR, d);
			str = df.format(c.getTime());
		}
		return str;
	}

	/**
	 * 根据类型来跳动当前时间
	 * 
	 * @param type
	 *            yy MM dd hh mm ss
	 * @param i
	 * @return
	 */
	public static Date dateAdd(String type, int i) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		Calendar c = Calendar.getInstance();
		if (type.equals(SECOND)) {
			int s = c.get(Calendar.SECOND);
			s = s + i;
			c.set(Calendar.SECOND, s);
			date = c.getTime();
		} else if (type.equals(MINUTE)) {
			int d = c.get(Calendar.MINUTE);
			d = d + i;
			c.set(Calendar.MINUTE, d);
			date = c.getTime();
		} else if (type.equals(HOUR)) {
			int d = c.get(Calendar.HOUR);
			d = d + i;
			c.set(Calendar.HOUR, d);
			date = c.getTime();
		} else if (type.equals(DAY_OF_MONTH)) {
			int d = c.get(Calendar.DAY_OF_MONTH);
			d = d + i;
			c.set(Calendar.DAY_OF_MONTH, d);
			date = c.getTime();
		} else if (type.equals(MONTH)) {
			int d = c.get(Calendar.MONTH);
			d = d + i;
			c.set(Calendar.MONTH, d);
			date = c.getTime();
		} else if (type.equals(YEAR)) {
			int d = c.get(Calendar.YEAR);
			d = d + i;
			c.set(Calendar.YEAR, d);
			date = c.getTime();
		}
		return date;
	}

	/**
	 * ʱ��ƫ������
	 */
	public static String getTime(int skipDay) {
		GregorianCalendar cal = new GregorianCalendar();
		cal.setTime(new Date());

		cal.add(GregorianCalendar.DAY_OF_MONTH, skipDay);
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");

		return dateFormat.format(cal.getTime());
	}

	/**
	 * ������������
	 */
	public static long subtraction(Date minuend, Date subtrahend) {

		long daterange = minuend.getTime() - subtrahend.getTime();
		long time = 1000 * 3600 * 24;

		return (daterange % time == 0) ? (daterange / time)
				: (daterange / time + 1);
	}

	public static long getM(Date date) {
		GregorianCalendar cal = new GregorianCalendar();
		cal.setTime(date);
		return cal.get(GregorianCalendar.DAY_OF_WEEK);
	}

	public static String getLastDate(String temp) {
		// ��temp�ǿ�����ǰ������
		if (temp == null || temp.equals("")) {
			temp = "1";
		}
		int i = Integer.parseInt(temp);
		DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
		Calendar grc = Calendar.getInstance();
		grc.add(GregorianCalendar.DATE, -i);
		return dateFormat.format(grc.getTime());
	}

	/**
	 * ��ȡ��һ������ڣ���4���ò�ѯ���������
	 */
	public static String getLastYearDate() {

		Calendar c = Calendar.getInstance();
		int y = c.get(Calendar.YEAR);
		String year = String.valueOf(y - 1);
		return year;
	}

	/**
	 * ��ȡ�ϸ��µ����ڣ���4���ò�ѯ���������
	 */
	public static String getLastMonthDate() {

		Calendar c = Calendar.getInstance();
		int y = c.get(Calendar.YEAR);
		int m = c.get(Calendar.MONTH) + 1;
		String month = null;
		String year = String.valueOf(y);
		if (m > 1) {
			if (m > 10) {
				month = String.valueOf(m - 1);
			} else {
				month = "0" + String.valueOf(m - 1);
			}
		} else {
			year = String.valueOf(y - 1);
			month = String.valueOf(12);
		}

		return year + "-" + month;
	}

	/**
	 * ��ȡǰһ������ڣ���4���ò�ѯ���������
	 * 
	 * @return
	 */
	public static String getLastDayDate() {
		Calendar c = Calendar.getInstance();
		int y = c.get(Calendar.YEAR);
		int m = c.get(Calendar.MONTH) + 1;
		int d = c.get(Calendar.DAY_OF_MONTH);
		int days = 0;
		if (m > 1) {
			days = getMonthsDays(m - 1, y);
		} else {
			days = 31;
		}
		String day = null;
		String month = null;
		String year = String.valueOf(y);
		if (d > 1) { // ����1��
			day = String.valueOf(d - 1);
			if (m > 9) {
				month = String.valueOf(m);
			} else {
				month = "0" + String.valueOf(m);
			}
		} else if ((d < 2) && (m < 2)) { // һ��һ��
			day = String.valueOf(31);
			month = String.valueOf(12);
			year = String.valueOf(y - 1);
		} else if ((d < 2) && (m > 2)) {
			day = String.valueOf(days);
			if (m > 10) {
				month = String.valueOf(m - 1);
			} else {
				month = "0" + String.valueOf(m - 1);
			}
		}

		return year + "-" + month + "-" + day;
	}

	/**
	 * �ж��Ƿ�����
	 */
	public static boolean isLeapYear(int year) {
		if ((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 4) == 0)
				&& ((year % 400) == 0)) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * ��ȡÿ���µ�����
	 * 
	 * @param month
	 * @param year
	 * @return
	 */
	public static int getMonthsDays(int month, int year) {
		if ((isLeapYear(year) == true) && (month == 2)) {
			return 29;
		} else if ((isLeapYear(year) == false) && (month == 2)) {
			return 28;
		}

		if ((month == 1) || (month == 3) || (month == 5) || (month == 7)
				|| (month == 8) || (month == 10) || (month == 12)) {
			return 31;
		}
		return 30;
	}

	public static String getWeekDay() {
		DateFormatSymbols symboles = new DateFormatSymbols(Locale.getDefault());
		symboles.setShortWeekdays(new String[] { "", "7", "1", "2", "3", "4",
				"5", "6" });
		SimpleDateFormat date = new SimpleDateFormat("E", symboles);
		return date.format(new Date());
	}

	/**
	 * ��ȡ��
	 */
	public static int getYear() {
		Calendar c = Calendar.getInstance();
		return c.get(Calendar.YEAR);
	}

	/**
	 * ��ȡ��
	 * 
	 * @return
	 */
	public static int getMonth() {
		Calendar c = Calendar.getInstance();
		return c.get(Calendar.MONTH);
	}

	/**
	 * ��ȡ��
	 * 
	 * @return
	 */
	public static int getDay() {
		Calendar c = Calendar.getInstance();
		return c.get(Calendar.DAY_OF_MONTH);
	}

	public static String getLastMonthDay(int lastmonths) {
		int month = getMonth() + 1;
		if (month - lastmonths > 0) {
			return String.valueOf(getYear()) + "-"
					+ String.valueOf(month - lastmonths) + "-1";
		} else {
			return String.valueOf(getYear() - 1) + "-"
					+ String.valueOf(12 + month - lastmonths) + "-1";
		}
	}

	/**
	 * 获取当前时间
	 * 
	 * @return 当前时间
	 * 
	 * @author weiZhi.zeng
	 * @Date:2010-8-26
	 */
	public static Date getCurrentDate() {
		return new Date();
	}

	/**
	 * 获得当前年月
	 * 
	 * @param args
	 * @author junWu.zhu
	 * @Date: 2010-12-27
	 */
	public static String getCurrentMonth() {
		return new SimpleDateFormat("yyyy-MM").format(new Date());
	}

	/**
	 * 获得添加月份后所得时间
	 * 
	 * @param monthLength
	 * @return
	 */
	public static Date monthAdd(String monthLength) {
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.MONTH, Integer.valueOf(monthLength));
		return calendar.getTime();
	}

	/**
	 * 获得添加月份后所得时间
	 * 
	 * @param monthLength
	 * @return
	 */
	public static Date monthAdd(int monthLength) {
		return monthAdd(""+monthLength);
	}

	/**
	 * 获得指定添加日期(年，月，日，时，分，秒)后所得时间
	 * 
	 * @param calendarType
	 *            日期对象
	 * @param
	 * @return
	 */
	public static Date dateAdd(int calendarType, int monthLength) {
		Calendar calendar = Calendar.getInstance();
		calendar.add(calendarType, monthLength);
		return calendar.getTime();
	}

	/**
	 * 获取当月第15天
	 * 
	 * @return
	 */
	public static String getMindDayOfMonth() {
		String str = "";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar lastDate = Calendar.getInstance();
		lastDate.set(Calendar.DATE, 15);// 设为当前月的15 号
		str = sdf.format(lastDate.getTime());
		return str;
	}

	/**
	 * 返回一月中最后一天日期
	 * 
	 * @param time
	 *            传入格式为 yyyy-mm-dd
	 * @return
	 */
	public static String getMonthLastDay(int year, int month) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cl = Calendar.getInstance();
		cl.set(Calendar.YEAR, year);
		cl.set(Calendar.MONTH, month);
		cl.set(Calendar.DATE, 1);// 设为当前月1号
		cl.add(Calendar.DATE, -1);// 减去一天，变为当月最后一天
		return sdf.format(cl.getTime());
	}

	/**
	 * 只获取当前时间
	 * 
	 * @param args
	 */
	public static String getCurrentTime() {
		return new SimpleDateFormat("hh:mm:ss").format(getCurrentDate());
	}

	/**
	 * @param formatter
	 *            格式
	 * @param calendarType
	 *            日期对象 : Calendar
	 * @param skip
	 *            累加数
	 * @return
	 */
	public static Date getSkipDate(String formatter, int calendarType, int skip) {
		Date date = null;
		try {
			date = new SimpleDateFormat().parse(formatDateTime(formatter,
					dateAdd(calendarType, skip)));
		} catch (ParseException e) {

		}
		return date;
	}

	/**
	 * 计算在当前时间之前日期相差几个月
	 * 
	 * @param lastDate
	 *            在当前之前的时间
	 * @return
	 */
	public static long getMonthNum(Date beforeDate) {
		Date nowDate = new Date();
		long l = nowDate.getTime() - beforeDate.getTime();
		long day = l / (24 * 60 * 60 * 1000) / 30;
		return day;
	}

	/**
	 * 将数字转换为时间(hh:mm:ss)
	 * 
	 * @return
	 */
	public static String getSecondToTime(long seconds) {
		Calendar cl = Calendar.getInstance();
		cl.setTimeInMillis(seconds * 1000);
		cl.add(Calendar.HOUR, -8);
		return cl.getTime().toLocaleString().split(" ")[1];
	}

	/**
	 * 将数字转换为 分:秒
	 */
	public static String getSecondToMinutesSeconds(long seconds) {
		long minute = seconds / 60;
		long second = seconds % 60;
		return minute + ":" + (+second <= 9 ? "0" + second : second).toString();
	}

	public static void main(String args[]) {
		//System.out.println(formatDateTime("yyyy-MM-dd HH:mm:ss",getCurrentDate
		// ()));
		// System.out.println(dateAdd(DAY_OF_MONTH,11));

		// System.out.println(dateCompare(getMindDayOfMonth()));
		// System.out.println(getCurrentTime());
		// System.out.println(getLastDayDate());
		// System.out.println(getLastMonthDate());
		// System.out.println(skipDateTime(getCurrentDate(), 1));
		// System.out.println(dateStrAdd(DateUtil.DAY_OF_MONTH,1));
		// System.out.println(DateUtil.formatDateTime("yyyy-MM-dd", DateUtil
		// .skipDateTime(DateUtil.getCurrentDate(), -7)));
		// System.out.println(DateUtil.formatDateTime("yyyy-MM-dd",
		// dateAdd(Calendar.MONTH, -5)));
		// System.out.println(DateUtil.formatDateTime("yyyy-MM-dd",
		// dateAdd(MONTH, -5)));
		// System.out.println(DateUtil.formatDateTime("yyyy-MM-dd",DateUtil.
		// dateAdd(
		// Calendar.DAY_OF_MONTH, -7)));
		// System.out.println(DateUtil.formatDateTime("yyyy-MM-dd",
		// DateUtil.dateAdd(
		// Calendar.DAY_OF_MONTH, 1)));
		// System.out.println(getSecondToTime(60));
		// System.out.println(getMonthLastDay(2011,3));
		// System.out.println(getYear());

		System.out.println(DateUtil.formatDateTime("yyyy-MM-dd", DateUtil
				.dateAdd(Calendar.MONTH, -1)));
		System.out.println(Calendar.getInstance().get(Calendar.MONTH) + 1);
		System.out.println(getSecondToTime(125));
		System.out.println(getSecondToMinutesSeconds(230));
	}

}
